<template>
	<gui-page ref="guiPage" :customHeader="true">
		<!-- 导航 -->
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left" :leftType="'1'" @clickLeftBack="clickLeftBack"
				:title="$t('whether.fsBagFeeding')" scanType="0"></nav-bar-custom>
		</template>
		<template v-slot:gBody>
			<view class="barcodeSplitting" :style="'height: calc(100vh - ' + navHeight + 'px);'">
				<!-- 卡片模块 -->
				<scroll-view :show-scrollbar="false" :scroll-y="true" class="scroll element-auto">
					<view style="height: 15rpx"></view>
					<view v-if="data.barcodeInfo" class="card-boxCustom">
						<view class="card-body">
							<view class="custom-card-title">
								<text class="title-line"></text>
								{{ $t('pageTranslation.plsScanBarcodeInfo') }}
							</view>
							<view class="custom-card-itemOne">
								<text class="body-item-title">{{ $t('distributedEnter.materialCoded') }}：</text>{{
									data.barcodeInfo.barcode }}
							</view>
							<view class="custom-card-itemOne">
								<text class="body-item-title">{{ $t('distributedEnter.materialCode') }}：</text>
								{{ data.barcodeInfo.materialCode }}
							</view>
							<view class="custom-card-itemOne">
								<text class="body-item-title">{{ $t('distributedEnter.materialName') }}：</text>
								{{ data.barcodeInfo.materialName }}
							</view>
							<view class="custom-card-itemOne">
								<text class="body-item-title">{{ $t('distributedEnter.materialSpec') }}：</text>{{
									data.barcodeInfo.materialSpec }}
							</view>
							<view class="custom-card-itemOne">
								<view class="card-item-50">
									<text class="body-item-title">{{ $t('distributedEnter.uom') }}：</text>
									{{ data.barcodeInfo.unit }}
								</view>
								<view class="card-item-50">
									<text class="body-item-title">{{ $t('distributedEnter.qty') }}：</text>
									{{ data.barcodeInfo.currentQty }}
								</view>
							</view>
							<view class="custom-card-itemOne">
								<text class="body-item-title">{{ $t('translationImage.warehouseSubordinate') }}：</text>
								{{ data.barcodeInfo.warehouseName }}
							</view>
							<view class="custom-card-itemOne">
								<text class="body-item-title">{{ $t('multilingual.locationBelonged') }}：</text>
								{{ data.barcodeInfo.locationCode }}
							</view>


							<view class="custom-card-itemTwo" style="padding: 20rpx 0;">
								<text class="item-info-title" style="width: 180rpx;">
									<text class="required-color">*</text>{{ $t('distributedEnter.qty') }}：
								</text>
								<uni-easyinput class="uni-mt-5" v-model="data.qty" @blur="changeQty"
									:placeholder="$t('distributedEnter.pleaseMaterialQty')"></uni-easyinput>
								<text style="margin-left: 20rpx;color: brown;font-weight: 600;">kg</text>
							</view>


						</view>
					</view>
				</scroll-view>


				<!-- 底部确定按钮 -->
				<view class="page-bottom-box">
					<view class="page-bottomBtn bottomBtn-bgcolor-green" @click="confirmFn">{{ $t('calendar.submit')
					}}
					</view>
				</view>
			</view>
		</template>
	</gui-page>
</template>

<script setup>
import {navigate,navigateBack} from '@/utils/routerSkip.js';
import pdaScan from '@/hooks/pdaScan.js'
import {useStore} from "vuex";
import {DEFAULT_WAREHOUSECODE,DEFAULT_WAREHOUSEID,OPERATION_COMMIT,OPERATION_SCAN} from '@/constant/index.js'
import {getDataDictionaryFn} from '@/utils/index.js'
import storageBin from '@/components/storageBin.vue'
import comboGrid from '@/components/comboGrid.vue'
import {onShow} from '@dcloudio/uni-app';
import {basPdaOperationLogFn} from '@/utils/index.js';
import {barcodeManagementScan,pvcTonInput,fsCardTonInput} from '@/api/api.js'
import {ref,reactive,onMounted,watch,computed,toRaw} from 'vue';
import {onBackPress} from '@dcloudio/uni-app';

//JS国际化引入
import {useI18n} from 'vue-i18n';

const {t} = useI18n();
let inputDialog = ref(null)

components: {
	storageBin,
		comboGrid
}
const storageBinRef = ref(null)
const comboGridRef = ref(null)
let store = useStore();

const navHeight = computed(() => {
	return store.state.navHeight
})



const data = reactive({
	barcodeInfo: null,
	barcode: '',
	qty: 0

})

onMounted(() => {
	getCode('FSCARD', '’');
})




const changeQty = () => {
	if (data.barcodeInfo.currentQty < data.qty) {
		uni.showToast({
			title: t('whether.cannotExceedThe'),
			icon: "none"
		});
		return
	}
	data.barcodeInfo.qty = data.qty
}


const getCode = (code, type) => {
	if (!code) {
		uni.showToast({
			title: t('stockManage.pleaseScanCode'),
			icon: "none"
		});
		return
	}
	let parmes = {
		current: 1,
		size: 99999,
		materialCode: null,
		materialName: null,
		locationCode: null,
		barcode: code,
		barcodeTypeCode: null
	}
	barcodeManagementScan(parmes).then(res => {
		try {
			let inputParameter = JSON.stringify(parmes)
			let returnParameter = JSON.stringify(res)
			let operationPicture = '吨包投料扫描条码'
			let callInterface = res.rquestUrl
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: res.code, //返回状态
				errorMessage: res.msg, //错误信息
				isPass: res.code == 0 ? 'Y' : 'N', //是否成功 Y N
				operationType: OPERATION_SCAN,
				module: 'WMS',
				source: "PDA",
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) { }
		console.log(res)
		if (res.code == 0) {

			if (res.data.barcodeStatus != 'inStock') {
				uni.showToast({
					title: t('whether.barcodeIsNot'),
					duration: 3000,
					mask: true,
					icon: 'error'
				})

				return;

			} else if (res.data.materialCode != '32CMF01') {
				uni.showToast({
					title: t('whether.slottedAshCan'),
					duration: 3000,
					mask: true,
					icon: 'error'
				})

				return;
			}

			data.barcodeInfo = res.data
			// store.commit('addTonBagFeeding', data.barcodeInfo)
		} else {
			data.barcodeInfo = undefined
			uni.showToast({
				title: res.msg,
				icon: "none"
			});
		}
	})
}



// 提交
const confirmFn = () => {
	if (data.qty <= 0) {
		uni.showToast({
			title: t('hardwareOut.pleaseQty'),
			icon: "none"
		});
		return
	}

	if (data.barcodeInfo.currentQty < data.qty) {
		uni.showToast({
			title: t('whether.cannotExceedThe'),
			icon: "none"
		});
		return
	}
	// 添加加载框
	uni.showLoading({
		title: 'loading',
		mask: true
	});

	if (data.qty > 0) { //选择了PVC

		var parmesFs = {
			barcode: "FSCARD",
			materialCode: "32CMF01",
			lstBarcodeInfo: []

		}

		parmesFs.lstBarcodeInfo.push({ "currentQty": data.qty })
		fsCardTonInput(parmesFs).then(res => {
			try {
				let inputParameter = JSON.stringify(parmes)
				let returnParameter = JSON.stringify(res)
				let operationPicture = '开槽灰吨包投料'
				let callInterface = res.rquestUrl
				let opertionParmes = {
					inputParameter,
					returnParameter,
					operationPicture,
					callInterface,
					responseCode: res.code, //返回状态
					errorMessage: res.msg, //错误信息
					isPass: res.code == 200 ? 'Y' : 'N', //是否成功 Y N
					operationType: OPERATION_COMMIT,
					module: 'WMS',
					source: "PDA",
				}
				basPdaOperationLogFn(opertionParmes)
			} catch (error) { }
			if (res.ok == true) {
				uni.showToast({
					title: t('smashRemoval.submitSuccessfully'),
					icon: "none"
				});


			} else {
				uni.showToast({
					title: res.msg,
					icon: "none"
				});
			}
		})
	}
}


//导航栏左侧返回
const clickLeftBack = () => {
	uni.navigateBack({
		delta: 1
	});
	return
}

onBackPress((options) => {
	if (options.from == 'backbutton') {
		uni.navigateBack({
			delta: 1
		});
		return true
	}
})
</script>

<style lang="scss" scoped>
.barcodeSplitting {
	display: flex;
	flex-direction: column;
	height: calc(100vh - 88rpx);
	// height: 100vh;
}

.distributed-head {
	border-bottom-left-radius: 16rpx;
	border-bottom-right-radius: 16rpx;
}

.scroll {
	flex: 1;
	height: 2rpx;
}

.page-bottom-box {
	position: absolute;
	left: 0px;
	bottom: 0px;
	width: 100%;
}
</style>